package com.ruoyi.web.controller.clique;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.clique.domain.CliqueDetail;
import com.ruoyi.clique.service.ICliqueDetailService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 集团信息Controller
 * 
 * @author ruoyi
 * @date 2019-10-24
 */
@Controller
@RequestMapping("/clique/cliqueDetail")
public class CliqueDetailController extends BaseController
{
    private String prefix = "clique";

    @Autowired
    private ICliqueDetailService cliqueDetailService;

    @RequiresPermissions("clique:cliqueDetail:view")
    @GetMapping()
    public String CliqueDetail()
    {
        return prefix + "/cliqueDetail";
    }

    /**
     * 查询集团信息列表
     */
    @RequiresPermissions("clique:cliqueDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CliqueDetail cliqueDetail)
    {
        startPage();
        List<CliqueDetail> list = cliqueDetailService.selectCliqueDetailList(cliqueDetail);
        return getDataTable(list);
    }

    /**
     * 导出集团信息列表
     */
    @Log(title = "导出集团信息", businessType = BusinessType.EXPORT)
    @RequiresPermissions("clique:cliqueDetail:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CliqueDetail cliqueDetail)
    {
        List<CliqueDetail> list = cliqueDetailService.selectCliqueDetailList(cliqueDetail);
        ExcelUtil<CliqueDetail> util = new ExcelUtil<CliqueDetail>(CliqueDetail.class);
        return util.exportExcel(list, "cliqueDetail");
    }

    /**
     * 新增集团信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存集团信息
     */
    @RequiresPermissions("clique:cliqueDetail:add")
    @Log(title = "新增集团信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CliqueDetail cliqueDetail)
    {
        return toAjax(cliqueDetailService.insertCliqueDetail(cliqueDetail));
    }

    /**
     * 修改集团信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CliqueDetail cliqueDetail = cliqueDetailService.selectCliqueDetailById(id);
        mmap.put("cliqueDetail", cliqueDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存集团信息
     */
    @RequiresPermissions("clique:cliqueDetail:edit")
    @Log(title = "修改集团信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CliqueDetail cliqueDetail)
    {
        return toAjax(cliqueDetailService.updateCliqueDetail(cliqueDetail));
    }

    /**
     * 删除集团信息
     */
    @RequiresPermissions("clique:cliqueDetail:remove")
    @Log(title = "删除集团信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cliqueDetailService.deleteCliqueDetailByIds(ids));
    }

    @RequiresPermissions("clique:cliqueDetail:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<CliqueDetail> util = new ExcelUtil<CliqueDetail>(CliqueDetail.class);
        return util.importTemplateExcel("集团信息模板");
    }

    @Log(title = "导入集团信息", businessType = BusinessType.IMPORT)
    @RequiresPermissions("clique:cliqueDetail:import")
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<CliqueDetail> util = new ExcelUtil<CliqueDetail>(CliqueDetail.class);
        List<CliqueDetail> userList = util.importExcel(file.getInputStream());
        String operName = ShiroUtils.getSysUser().getUserId().toString();
        String message = cliqueDetailService.importCliqueDetail(userList, operName);
        return AjaxResult.success(message);
    }
}
